package com.jml.netty.version4;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;

//
public class ServerHandler extends SimpleChannelHandler {

	//接受客户端数据
	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
		super.messageReceived(ctx, e);
		System.out.println("messageReceived");
		System.out.println("服务端获取客户端发来的参数:"+e.getMessage());
		e.getChannel().write("hello");
	}
	//接收端出现异常
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
		super.exceptionCaught(ctx, e);
		System.out.println("接受数据发生异常");

	}

	//必须是连接已经建立,关闭通道的时候才会触发.
	@Override
	public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e)
			throws Exception {
		super.channelDisconnected(ctx, e);
		System.out.println("channelDisconnected：建立连接后，关闭调用");
	}

	//通道被关闭的时候触发
	@Override
	public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
		super.channelClosed(ctx, e);
		System.out.println("channelClose：建不建立连接都调用");
	}


}
